#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
消息相关枚举类
"""

from enum import Enum, IntEnum


class MessageTypeEnum(IntEnum):
    """
    消息类型枚举
    """
    TEXT = 1    # 文本
    IMAGE = 2   # 图片
    FILE = 3    # 文件
    VOICE = 4   # 语音
    VIDEO = 5   # 视频
    SYSTEM = 6  # 系统消息
    
    @classmethod
    def from_str(cls, type_str):
        """
        从字符串转换为枚举值
        
        Args:
            type_str (str): 类型字符串
            
        Returns:
            MessageTypeEnum: 枚举值
        """
        type_map = {
            'text': cls.TEXT,
            'image': cls.IMAGE,
            'file': cls.FILE,
            'voice': cls.VOICE,
            'video': cls.VIDEO,
            'system': cls.SYSTEM
        }
        return type_map.get(type_str.lower(), cls.TEXT)
    
    @classmethod
    def to_str(cls, type_int):
        """
        从枚举值转换为字符串
        
        Args:
            type_int (int): 类型整数
            
        Returns:
            str: 类型字符串
        """
        type_map = {
            cls.TEXT: 'text',
            cls.IMAGE: 'image',
            cls.FILE: 'file',
            cls.VOICE: 'voice',
            cls.VIDEO: 'video',
            cls.SYSTEM: 'system'
        }
        return type_map.get(type_int, 'text')


class MessageDirectionEnum(IntEnum):
    """
    消息方向枚举
    """
    RECEIVED = 1  # 接收
    SENT = 2      # 发送
    
    @classmethod
    def from_str(cls, direction_str):
        """
        从字符串转换为枚举值
        
        Args:
            direction_str (str): 方向字符串
            
        Returns:
            MessageDirectionEnum: 枚举值
        """
        direction_map = {
            'received': cls.RECEIVED,
            'incoming': cls.RECEIVED,
            'sent': cls.SENT,
            'outgoing': cls.SENT
        }
        return direction_map.get(direction_str.lower(), cls.SENT)
    
    @classmethod
    def to_str(cls, direction_int):
        """
        从枚举值转换为字符串
        
        Args:
            direction_int (int): 方向整数
            
        Returns:
            str: 方向字符串
        """
        direction_map = {
            cls.RECEIVED: 'received',
            cls.SENT: 'sent'
        }
        return direction_map.get(direction_int, 'sent')


class ChatTypeEnum(IntEnum):
    """
    聊天类型枚举
    """
    PRIVATE = 1  # 私聊
    GROUP = 2    # 群聊
    
    @classmethod
    def from_str(cls, chat_type_str):
        """
        从字符串转换为枚举值
        
        Args:
            chat_type_str (str): 聊天类型字符串
            
        Returns:
            ChatTypeEnum: 枚举值
        """
        chat_type_map = {
            'private': cls.PRIVATE,
            'group': cls.GROUP
        }
        return chat_type_map.get(chat_type_str.lower(), cls.PRIVATE)
    
    @classmethod
    def to_str(cls, chat_type_int):
        """
        从枚举值转换为字符串
        
        Args:
            chat_type_int (int): 聊天类型整数
            
        Returns:
            str: 聊天类型字符串
        """
        chat_type_map = {
            cls.PRIVATE: 'private',
            cls.GROUP: 'group'
        }
        return chat_type_map.get(chat_type_int, 'private')